package com.quanyue.music.template.controller;

import com.quanyue.auto.util.ServiceResult;
import com.quanyue.auto.web.Principal;
import com.quanyue.music.domain.entity.FormId;
import com.quanyue.music.template.service.TemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.time.LocalDate;

@Api(tags = "模板消息")
@RestController
@RequestMapping("/api")
public class TemplateController {
    @Autowired
    private TemplateService templateService;

    @ApiOperation(value = "保存form_id")
    @PostMapping(value = "/template/formId", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult <Boolean> saveFormId(@RequestBody FormId formId, @ApiIgnore Principal principal) {
        templateService.addFormId(formId, principal.getId());
        return ServiceResult.SUCCESS;
    }

    @ApiOperation(value = "查看当天formId数量")
    @GetMapping(value = "/template/formId", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult <Integer> selectFormId(@ApiIgnore Principal principal) {
        return ServiceResult.success(templateService.findFormIdCount(principal.getId(), LocalDate.now()));
    }
}
